package website.lucaswork.survey.api.controllers;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.NoHandlerFoundException;
import org.springframework.web.servlet.mvc.WebContentInterceptor;

@Component
public class SurveyApiWCI extends WebContentInterceptor {
	private final static DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 
	
	public SurveyApiWCI(){
		setRequireSession(false);
		setCacheSeconds(120);
		setSupportedMethods("GET","POST", "OPTIONS", "HEAD");
	}
	
	@InitBinder
	public void allowDateTypeBind(WebDataBinder binder) {
		binder.registerCustomEditor(Date.class, new CustomDateEditor(df, true));
	}
	
//	@RequestMapping(value="/**")
//	public String NoHandlerFoundHandler() throws NoHandlerFoundException {
//		throw new NoHandlerFoundException(null, null, null);
//	}
}
